/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package topcoder;

/**
 *
 * @author Mohamed.Azouz
 */
public class BadVocabulary {

    public int count(String bp, String bs, String bsu, String[] v) {
        int tot = 0;
        for (int i = 0; i < v.length; i++) {
            if (v[i].startsWith(bp) || v[i].endsWith(bs) || containsMiddle(bsu, v[i])) {
                tot++;
            }
        }
        return tot;
    }

    private boolean containsMiddle(String w, String t) {
        if (t.length() >= 3) {
            t = t.substring(1, t.length() - 1);
            return t.contains(w);
        }
        return false;
        
    }

    public static void main(String[] args) {
        BadVocabulary b = new BadVocabulary();
        String bp = "cut";
        String bs = "sore";
        String bsu = "scar";
        String[] v = {"scary", "oscar"};
        System.out.println(b.count(bp, bs, bsu, v));
    }
}
